<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="李愧愧">
    <title></title>
    <style>

    </style>
</head>

<body>
    <h1></h1>
    <script>
        var h1 = document.querySelector('h1');
        var targetTime = new Date("2021-02-12 00:00:00");

        setInterval(function () {
            var nowTime = new Date()
            var offsetTime = targetTime.getTime() - nowTime.getTime();
            // 转换为秒
            offsetTime = parseInt(offsetTime / 1000);

            var day = parseInt(offsetTime / (24 * 60 * 60));
            var hours = parseInt(offsetTime / 60 % 60);
            var minutes = parseInt( offsetTime % (60*60) / 60 ) 
            var second = parseInt(offsetTime % 60 );

            h1.innerText = "距离2021年春节还有"+day+"天"+hours+"小时"+minutes+"分钟"+second +"秒"
        },1000);
    </script>
</body>

</html>